//
//  UIView+ydw.m
//  OCAPPDemo
//
//  Created by 杨冬武 on 2021/4/22.
//

#import "UIView+ydw.h"
#import <objc/runtime.h>

@implementation UIView (ydw)

/*
+ (void)load {
    Method origin = class_getInstanceMethod([UIView class], @selector(hitTest:withEvent:));
    Method custom = class_getInstanceMethod([UIView class], @selector(ydw_hitTest:withEvent:));
    method_exchangeImplementations(origin, custom);
    
    origin = class_getInstanceMethod([UIView class], @selector(pointInside:withEvent:));
    custom = class_getInstanceMethod([UIView class], @selector(ydw_pointInside:withEvent:));
    method_exchangeImplementations(origin, custom);
}

- (UIView *)ydw_hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    NSLog(@"%@ hitTest", NSStringFromClass([self class]));
    UIView *result = [self ydw_hitTest:point withEvent:event];
    NSLog(@"%@ hitTest return: %@ tag = %ld", NSStringFromClass([self class]), NSStringFromClass([result class]), (long)result.tag);
    return result;
}

- (BOOL)ydw_pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    NSLog(@"%@ pointInside", NSStringFromClass([self class]));
    BOOL result = [self ydw_pointInside:point withEvent:event];
    NSLog(@"%@ pointInside return: %@", NSStringFromClass([self class]), result ? @"YES":@"NO");
    return result;
}
*/


- (UIViewController *)viewController {
    UIResponder *responder = self.nextResponder;
    while (responder) {
        if ([responder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)responder;
        }
        responder = responder.nextResponder;
    }
    return nil;
}

@end
